package com.ufox.exception;

import cn.hutool.core.util.StrUtil;
import com.ufox.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {


        String message = e.getMessage();

        if(StrUtil.isBlank(message)){
            message = "未知的异常!";
        }
        log.error(message);
        return Result.error(message);
    }
}
